# 基本异常捕语法获
from idlelib.run import MyRPCServer

# try:
#     f = open("F:/Python/demo08.txt", "r", encoding="utf-8")
#     f.close()
# except:
#     print("捕获到异常,采用w模式打开文件")
#     f=open("F:/Python/demo08.txt", "w", encoding="utf-8")
#     f.write("异常捕获")
#     f.close()
#     r=open("F:/Python/demo08.txt", "r", encoding="utf-8")
#     print(r.read())
#     r.close()

# 捕获指定异常

# try:
#     print(name)
# except NameError as error_name:
#     print("捕获到了变量未定义的异常")
#     print(error_name)

# 捕获多个异常
# try:
#     print(name)
#     1 / 0
# except (ZeroDivisionError,NameError) as e:
#     print("捕获到了除零异常或者变量未命名异常")
#     print(e)

# 异常的传递性
# def func01():
#     print("这是func01的开始")
#     num = 1 / 0
#     print("这是func01的结束")
#     return num
#
# def func02():
#     print("这是func02的开始")
#     func01()
#     print("这是func02的结束")
#
# def main():
#     try:
#         func02()
#     except Exception as e:
#         print(e)
# main()
# func02()
# 自定义模块
# import modle_demo01
# modle_demo01.func01(3, 5)

from modle_demo01 import func01
# from modle_demo02 import func01
# func01(4,5)

# import time
# print("测试1")
# time.sleep(5)
# print("测试2")

# 测试特殊变量__all__,__main__
# from modle_demo01 import *
# func01(3,4)
# func02(3,4)

# 测试导入自定义包
# import my_package.modle01
# import my_package.modle02
#
# my_package.modle01.func01()
# my_package.modle02.func04()
# 测试__all__变量
# from my_package import *
# modle01.func02()
# modle02.func03()
